package javaPersistence;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Properties;

public class DBConexConSoft {
	
protected static DBConexConSoft dbConexConfSoft = null;
	
	private Connection conexion;
	
	private Statement declaracion;
	
	public static DBConexConSoft getInstance(){
        if(dbConexConfSoft == null){
        	dbConexConfSoft = new DBConexConSoft();
        }
        return dbConexConfSoft;
    }
	
	public DBConexConSoft() {
		if(getConexion() == null && getDeclaracion() == null){
			System.out.println("Ingreso a constructor de DBConexConfSoft");
			try {
				Class.forName("com.mysql.jdbc.Driver");
				//Para el portatil
				String myURL = "jdbc:mysql://localhost:3307/consoftasociados";
				//Para el trabajo
				//String myURL = "jdbc:mysql://localhost:3306/consoftasociados";
				Properties userInfo = new Properties();
				userInfo.put("user", "root");
				userInfo.put("password", "master");
				Connection miconexion = DriverManager.getConnection(myURL, userInfo);
				Statement declaracion =	miconexion.createStatement();
				setConexion(miconexion);
				setDeclaracion(declaracion);
			} catch (ClassNotFoundException cnfe) {
				System.out.println("Error al cargar el driver:" + cnfe);
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
	}

	public Connection getConexion() {
		return conexion;
	}

	public void setConexion(Connection conexion) {
		this.conexion = conexion;
	}

	public Statement getDeclaracion() {
		return declaracion;
	}

	public void setDeclaracion(Statement declaracion) {
		this.declaracion = declaracion;
	}
	
	
	

}
